const UserService = require("./../service/UserService");

const UserController = {
  getUser: async (req, res) => {
    res.send({
      code: 200,
      message: "getUser",
      data: await UserService.getUser(),
    });
  },
  addUser: async (req, res) => {
    res.send({
      code: 200,
      message: "addUser",
      data: await UserService.addUser({
        ...req.body,
        name: req.body.name || "张三",
        age: req.body.age || 24,
        hobbies: req.body.hobbies || ["篮球", "足球", "乒乓球"],
        avatar: req.file?.path?.replaceAll("\\", "/"),
      }),
      ...req.status,
    });
  },
  updateUser: async (req, res) => {
    res.send({
      code: 200,
      message: "updateUser",
      data: await UserService.updateUser(req.params.id, req.body),
    });
  },
  delUser: async (req, res) => {
    res.send({
      code: 200,
      message: "delUser",
      data: await UserService.delUser(req.params.id),
    });
  },
};

module.exports = UserController;
